package com.airticketbooking.controller.user;

import com.airticketbooking.common.domain.PageDTO;
import com.airticketbooking.common.domain.R;
import com.airticketbooking.query.TicketPageQuery;
import com.airticketbooking.vo.TicketVO;
import com.airticketbooking.service.TicketService;
import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * @author Mr.J
 * @version 1.0.0
 * @date 2024/10/21
 * @desc
 */

@RestController
@RequiredArgsConstructor
@Api(tags = "用户端票据查询")
@RequestMapping("/air/user/ticket")
@Slf4j
public class UserTicketController {

	private final TicketService ticketService;

	private final RedisTemplate redisTemplate;

	/***
	 * @param ticketPageQuery
	 * @return: com.airticketbooking.common.domain.R<com.airticketbooking.common.domain.PageDTO < com.airticketbooking.domain.vo.TicketVO>>
	 * @Author: susu
	 * @date: 2024/11/9
	 * @since 1.0.0
	 * @Description:
	 */

	@GetMapping("/page")
	public R<PageDTO<TicketVO>> pageQuerylist(TicketPageQuery ticketPageQuery) {



//		String key = "tickets";
//		Integer pageStart = ticketPageQuery.getPageNo();
//		Integer pageSize = ticketPageQuery.getPageSize();
//		Integer pageEnd = (pageStart -1) * pageSize;
//		redisTemplate.opsForList().range(key, pageStart,pageEnd);
//
//		log.info("redisTemplate.opsForList().range(key, pageStart,pageEnd) = "
//				+ redisTemplate.opsForList().range(key, pageStart,pageEnd));

		Page<TicketVO> ticketVOList = ticketService.pageQuerylist(ticketPageQuery);
		PageDTO<TicketVO> pageDTO = new PageDTO<>();
		pageDTO.setList(ticketVOList.getResult());
		pageDTO.setTotal(ticketVOList.getTotal());

		return R.ok(pageDTO);
	}

	//	根据id查找票据
	@GetMapping("/getTicketById/{id}")
	public R<TicketVO> getTicketById(@PathVariable Integer id) {
		TicketVO ticketVO = ticketService.getTicketById(id);
		return R.ok(ticketVO);
	}


}
